<template>
  <Form
    ref="operateForm"
    :model="form"
    :rules="rules"
    @keydown.enter.native="handleSubmit"
    inline
    style="width: 100%">
    <FormItem prop="state" style="width: 15%">
      <Select v-model="form.state" placeholder="请选择启用状态" clearable>
        <Option value=0>
          启用
        </Option>
        <Option value=1>
          禁用
        </Option>
      </Select>
    </FormItem>
    <FormItem style="float: right">
      <Button @click="handleSubmit" icon="md-search" type="primary">
        搜索
      </Button>
    </FormItem>
  </Form>
</template>
<script>
export default {
  name: 'OperateForm',
  props: {
    stateRules: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      form: {
        state: ''
      }
    }
  },
  computed: {
    rules () {
      return {
        state: this.stateRules
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.operateForm.validate((valid) => {
        if (valid) {
          this.$emit('on-success-valid', {
            state: this.form.state
          })
        }
      })
    }
  }
}
</script>
